HealthKit Permission Behavior PRO
When using the Health module provided by the Scripting app to access iOS HealthKit data, it's important to understand how HealthKit handles authorization and how Scripting adapts to these behaviors. This document explains the authorization flow, Promise behavior, and best practices for handling missing permissions.
Key Characteristics of iOS HealthKit Authorization
-
No public API to check authorization status iOS does not provide any public API to determine whether a specific HealthKit data type has been authorized or denied. Apps cannot check this directly.
-
Authorization prompt appears only once per type The system will show a permission dialog only if the data type's status is
notDetermined. Once the user grants or denies access, the dialog will not reappear. -
No system-level error if access is denied If an app attempts to access unauthorized data, HealthKit will not throw a system error. Instead, some APIs return empty results, while others may reject the Promise.
Scripting App Behavior
Automatic Authorization Request
When you call any Health API that requires access to protected data, the Scripting app will automatically trigger the system permission dialog if any of the required types are not yet determined.
For example:
Promise Behavior by API
Code Examples
Example 1: Querying samples (returns empty array when unauthorized)
Example 2: Reading profile information (rejects if unauthorized)
Permission Merging on Multiple Calls
If you call multiple permission-requiring methods simultaneously using Promise.all, Scripting will automatically merge the required permissions into a single system dialog request. This improves user experience by avoiding repeated prompts.
Best Practices and UI Recommendations
Manual Authorization
Go to Health app > Data Access & Devices > Scripting, and make sure the necessary data types are enabled.
